<?php

class Application_Model_service_SanPhamService implements Application_Model_serviceInf_SanPhamServiceInf {
	protected $_name = "tb_sanpham";
	protected static $_instance=null;
	
	protected function __construct(){
		
	}
	public static function getInstance(){
		if(self::$_instance==null) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	
	/**
	 * @param unknown_type $tenSanPham
	 * @param unknown_type $maSanPham
	 * @param unknown_type $idDanhMuc
	 * @param unknown_type $giaGoc
	 * @param unknown_type $giaBan
	 * @param unknown_type $moTa
	 * @param unknown_type $chucNang
	 * @param unknown_type $chucNangKhac
	 * @param unknown_type $anh
	 */
	public function taoSanPham($tenSanPham, $maSanPham, $idDanhMuc, $giaGoc, $giaBan, $moTa, $chucNang, $chucNangKhac, $anh,$tinhTrang) {
		$result=0;
		$chucNangString='';
		foreach ($chucNang as $value) {
			$chucNangString=$chucNangString.$value.' ';
		}
		$anhString='';
		foreach ($anh as $value) {
			$anhString=$anhString.$value.' ';
		}
		
		// goi DAO luu xuong database
		$DAO=Application_Model_dataDAO_SanPhamDAO::getInstance();
		$result=$DAO->insertSanPham($tenSanPham, $maSanPham, $idDanhMuc, $giaGoc, $giaBan, $moTa, $chucNangString, $chucNangKhac, $anhString,$tinhTrang);
		return $result;
	}
	/**
	 * @param unknown_type $id
	 */
	public function loadSanPham($id) {
		$result=null;
		//goi DAO
		$DAO=Application_Model_dataDAO_SanPhamDAO::getInstance();
		$DAO instanceof Application_Model_dataDAOInf_SanPhamDAOInf;
		$result=$DAO->loadSanPham($id);
		return $result;
	}

	/**
	 * @param unknown_type $id
	 */
	public function xoaSanPham($id) {
		
	}
	/**
	 * @param int $limit
	 * @param int $page
	 * @param string $tenSanPham
	 * @param string $maDanhMuc
	 * @param int $giaBan
	 * @param int $maChucNang
	 */
	public function getListSanPham($limit, $page, $tenSanPham, $maDanhMuc, $giaBan, $maChucNang) {
		$result=array();
		//goi DAO
		$DAO=Application_Model_dataDAO_SanPhamDAO::getInstance();
		$DAO instanceof Application_Model_dataDAOInf_SanPhamDAOInf;
		$result=$DAO->loadListSanPham($limit,$page,$tenSanPham,$maDanhMuc,$giaBan,$maChucNang);
		return $result;
	}

	public function pages($limit, $page, $tenSanPham, $maDanhMuc, $giaBan, $maChucNang) {
		$result=0;
		//goi DAO
		$DAO=Application_Model_dataDAO_SanPhamDAO::getInstance();
		$DAO instanceof Application_Model_dataDAOInf_SanPhamDAOInf;
		$result=$DAO->pagesNum($limit,$page,$tenSanPham,$maDanhMuc,$giaBan,$maChucNang);
		return $result;
	}
	/**
	 * @param unknown_type $tenSanPham
	 * @param unknown_type $idDanhMuc
	 * @param unknown_type $moTa
	 * @param unknown_type $tinhTrang
	 */
	public function updateThongTinChung($id,$tenSanPham, $idDanhMuc, $moTa, $tinhTrang) {
		$result=false;
		//goi DAO
		$DAO= Application_Model_dataDAO_SanPhamDAO::getInstance();
		$DAO instanceof Application_Model_dataDAOInf_SanPhamDAOInf;
		$result=$DAO->updateThongTinChung($id,$tenSanPham,$idDanhMuc,$moTa,$tinhTrang);
		return $result;
	}


	


	
	

}

?>